#encoding=utf8
import numpy as np
import pandas as pd
import matplotlib as mpl
import matplotlib.pyplot as plt
from sklearn import svm
from sklearn.model_selection import train_test_split
from sklearn.metrics import accuracy_score

if __name__ == "__main__":
    train = pd.read_csv('../dataset/train_modified.csv')
    target = 'Disbursed'  # Disbursed的值就是二元分类的输出
    IDcol = 'ID'
    x_columns = [x for x in train.columns if x not in [target, IDcol]]
    X = train[x_columns]
    y = train['Disbursed']
    x_train, x_test, y_train, y_test = train_test_split(X, y, train_size=0.7, random_state=1)

    #clf = svm.SVC(C=0.1, kernel='linear', decision_function_shape='ovr')
    clf = svm.SVC(C=0.8, kernel='rbf', gamma=20, decision_function_shape='ovr')
    clf.fit(x_train, y_train)
    print clf.score(x_train, y_train)
    print 'train 准确率：', accuracy_score(y_train, clf.predict(x_train))
    print clf.score(x_test, y_test)
    print 'test 准确率：', accuracy_score(y_test, clf.predict(x_test))
    print 'decision_function:\n', clf.decision_function(x_train)
    print '\npredict:\n', clf.predict(x_train)

